var fs = require("fs");

function getRandomCDF(data) {
	var portion = data.portion;
	var range = data.range;

	var unit;
	switch(data.unit) {
		case 'K':
			unit = 1000;
			break;
		case 'M':
			unit = 1000000;
			break;
		case 'G':
			unit = 1000000000;
			break;
		default:
			unit = 1;
	}

	var random = Math.random();
	for(var i = 0; i < portion.length; i++) {
		if(random < portion[i]) {

			var value = getRandomValue(range[i], range[i + 1]) * unit;
			return value;
		}
	}
}

function getRandomValue(min, max) {
	var range = max - min;
	var value = min + Math.random() * range;
	return value;
}

module.exports = getRandomCDF; 